package dao;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import entity.Voyage;

@Stateless
@Local
public class VoyageDaoJpa implements VoyageDao {

	private EntityManager entityManager;

	@PersistenceContext(unitName = "MyPersistentUnit")
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Voyage> getAllVoyages() {
		Query query = entityManager.createQuery("select v from Voyage as v");
		List<Voyage> listeVoyage = query.getResultList();
		return listeVoyage;
	}

	@Override
	public Voyage getVoyageById(long id) {
		Voyage v = entityManager.find(Voyage.class, id);
		return v;
	}

}
